import wepy from 'wepy'
export default class extends wepy.mixin {
  data = {
    // 分页页数
    pageIndex: '1',
    // 分页大小
    pageSize: '10',
    // 分类id
    categoryId: '',
    // 关键系搜索
    keyword: '',
    // 会员id
    memberId: '',
    // 排序类型
    searchType: '',
    // 分类数据
    getGoodsListInfo: [],
    // 商品列表的总数
    isLoading: false,
    total: this.total,
  }
  methods = {
    // 跳转到商品详情
    goGoodsDatils(id) {
      wepy.navigateTo({
        url: '../../pages/goodsDatils/gooddatils?id=' + id,
      })
    },
  }
  computed = {
    isTotal() {
      if (this.getGoodsListInfo != null) {
        let numm = this.getGoodsListInfo.length
        return numm
      }
    },
  }
  onLoad(option) {
    console.log(option,'商品列表启动了')
    // this.getUserInfo()
		this.categoryId=option.categoryId;
		this.getGoodsList()
  }
  // 获取商品列表数据
  async getGoodsList(callback) {
    const res = await wepy.post('baseRest/getGoodsList', {
      pageIndex: this.pageIndex,
      pageSize: this.pageSize,
      categoryId: this.categoryId,
      keyword: this.keyword,
      memberId: this.memberId,
      searchType: this.searchType,
    })
    console.log(res)

    if (res.statusCode != 200) {
      return wepy.noToast('获取数据失败')
    }

    this.getGoodsListInfo = [...this.getGoodsListInfo, ...res.data.data]
    this.$apply()
    callback && callback()
    console.log(this.getGoodsListInfo)
  }
  // 触底触发的事件
  onReachBottom() {
    console.log('已触底')
    //判断数据是否正在请求中
    if (this.pageIndex * this.pageSize >= this.total) {
      return
    }
    let num = parseInt(this.pageIndex)
    num++
    this.pageIndex = num.toString()
    this.getGoodsList()
  }
}
